<?php 
@session_start();
	require_once('../execute/auth.php');	
	require_once('execute/inc/config.inc');
	
	?>
	<!doctype html>
<html>
	

<head>
	<title>TECHEDU Dashboard</title>
	<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
	<link rel="stylesheet" type="text/css" href="../assets/css/bootstrap.min.css" />
	<link rel="stylesheet" type="text/css" href="../assets/css/bootstrap-responsive.css" />
	<link rel="stylesheet" type="text/css" href="../assets/css/style.css" />
	<link rel="stylesheet" href="../assets/css/font-awesome.css" type="text/css">
	<link rel="stylesheet" href="../assets/css/editor_style.css" type="text/css">
	
	<script type="text/javascript" src="../assets/js/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="../assets/js/main.js"></script>
	<script type="text/javascript" src="../assets/js/bootstrap.js"></script>
	<script type="text/javascript" src="../assets/js/bootstrap-tooltip.js"></script>
	<script type="text/javascript" src="../assets/js/bootstrap.file-input.js"></script>
	<script type="text/javascript" src="../assets/js/chart.js"></script>
	<script type="text/javascript" src="../assets/js/bootstrap-modal.js"></script>
	<script type="text/javascript" src="../assets/js/bootstrap-typeahead.js"></script>
	<script type="text/javascript" src="../assets/js/bootstrap-wysiwyg.js"></script>
	<script src="https://mindmup.s3.amazonaws.com/lib/jquery.hotkeys.js"></script>
	<script type="text/javascript">
		$(function(){
			$("#editor").wysiwyg();
			$('#editor').cleanHtml();
			$('.btn').tooltip();
		});
	</script>
	<script type="text/javascript">
		$(function(){
			$("#add_news_btn").live("hover",function(){
				var txt = $("#editor").html();
				$("#show").text(txt);
			});
		});
	</script>
	<script type="text/javascript">
		$(function(){
			$("#add_news_btn").live("click",function(){
				var txt = $("#editor").html();
				$("#show").text(txt);
			});
		});
	</script>
	<script type="text/javascript">
		$(function(){
			$(".btn_insert").live("click",function(){
				$("#imgbtn").click();
			});
		});
	</script>
	<script type="text/javascript">
		$(function(){
			$("#show_link").live("click",function(){
				$("#link").show();
			});
		});
	</script>
	<script type="text/javascript">	
		$(function(){
			$('html').click(function() {
				$("#link").hide();
			});
			$("#link").click(function(event) {
				  event.stopPropagation();
			});
		});
		</script>
	<!--[if lt IE 9]>
 <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
 <![endif]-->
 
  
  
  <script type = "text/javascript">
 
 $(function() {
	
	//call the function onload
	getdata(1);
});
 
function getdata( pageno ){
	
	var targetURL = '../pagination/search_results_admin.php?page=' + pageno;   

	$('#retrieved-data').html('<p><img src="pagination/ajax-loader.gif" /></p>');        
	$('#retrieved-data').load( targetURL ).hide().fadeIn('slow');
}      
</script>

<script type="text/javascript">
$(function(){
	$('.delete_update').live("click",function() 
			{
			var ID = $(this).attr("id");
			var dataString = 'news_id='+ ID;
			 
			if(confirm("SURE YOU WANT TO DELETE THIS NEWS? THERE IS NO UNDO!"))
						
			{
			 $.ajax({
			 type: "POST",
			 url: "execute/delete_news.php",
			 data: dataString,
			 cache: false,
			 success: function(html){
			 $(".bar"+ID).css('background','gray');
			 $(".bar"+ID).slideUp('6000', function() {
			 $(this).remove();
			 
			 $('#delete_result').show(300,function(){
				 $('#delete_result').html(html);	
			 });
			 
			 
			 });
			 }
			});
					
			
			}
			
			return false;
			});
	
});
</script>
<script type="text/javascript">
	$(function(){
		$("#add_new_cat").live("click",function(){
			$("#news_cat").hide();
			$("#add_new_cat").hide();
			$("#add_new").show();
			$("#cat").focus();	
		});	
	});
	$(function(){
		$("#cancel").live("click",function(){
			$("#add_new").hide();
			$("#news_cat").show();
			$("#add_new_cat").show();	
		});	
	});
</script>

<script type="text/javascript">
	$(function(){
		$("#submit_cat").live("click",function(){
			var cat = $("#cat").val();
			if(cat != ''){
			var dataStr = 'catname='+cat;
			//window.location = "http://localhost/tech-edu/members/execute/add_category.php?catname=" +cat;
			$.ajax({
		          type: "get",
		          url: "execute/add_category.php",
		          data: dataStr,
		       	  success: function(html){
			       	 $('#add_new').hide();
		             $('#news_cat_new').show().html(html);
		           }
		    });
			}
			else{
				alert ("Please Fill in the field!");
				return false;
				}
		});
		
	});
</script>

<script type="text/javascript">
$(function(){
   $('.push_edit').live("click",function(){
      var newid = $(this).attr("id");
      var dataString='post_id='+ newid;
       $.ajax({
          type: "POST",
          url: "execute/news_edit.php",
          data: dataString,
       	  success: function(html){
             $('#myModal').modal();
             $('.something').show().html(html);
           }
    });
});
});
</script>
</head>
<body>

	<div class="navbar navbar-fixed-top m-header">
		<div class="navbar-inner m-inner">
			<div class="container-fluid">
				<a class="brand m-brand" href="./index.html" style="margin-left:10px;"><small>TECHNATION</small></a>
				
	 <form class="form-search m-search span5">
					<input type="text" placeholder="Type to search" class="span5 search-query">
				</form>
				<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
		 <span class="icon-bar"></span>
		 <span class="icon-bar"></span>
		 <span class="icon-bar"></span>
		 </button>
		 
				<div class="nav-collapse collapse">
					<div class="btn-group pull-right">
				 <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
			 		<i class="icon-user"></i> &nbsp;&nbsp;<?php echo $_SESSION['SESS_MEMBER_EMAIL']; ?>
			 		<span class="caret"></span>
				 </a>
				 <ul class="dropdown-menu">
			 		<li><a href="#"><i class="icon-user"></i>&nbsp;Profile</a></li>
			 		<li><a href="#"><i class="icon-cog"></i>&nbsp;Settings</a></li>
	 		 				<li class="divider"></li>
			 		<li><a href="../execute/logout.php"><i class="icon-off"></i>&nbsp;Logout</a></li>
				 </ul>
			 	</div>
	 	</div>
			</div>
		</div>
	</div>
	<div class="m-top"></div>
	<aside class="sidebar">
		<ul class="nav nav-tabs nav-stacked">
			<li>
				<a href="index.php">
					<div>
						<div class="ico">
							<img src="../assets/img/ico/ico-home.png">
						</div>
						<div class="title">
							Home
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			
			<li class="active">
				<a href="notification.html">
					
					<div>
						<div class="ico">
							<img src="../assets/img/ico/news-icon.png">
						</div>
						<div class="title">
							News
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			
			<li class="">
				<a href="courses.php">
					
					<div>
						<div class="ico">
							<img src="../assets/img/ico/ico-notification.png">
						</div>
						<div class="title">
							Courses
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			<li class="">
				<a href="form.html">
					<div>
						<div class="ico">
							<img src="../assets/img/ico/ico-setting.gif">
						</div>
						<div class="title">
							Setting
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			<li class="">
				<a href="order.html">
					<div>
						<div class="ico">
							<img src="../assets/img/ico/ico-order.gif">
						</div>
						<div class="title">
							Order
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			<li class="">
				<a href="media.html">
					<div>
						<div class="ico">
							<img src="../assets/img/ico/ico-media.gif">
						</div>
						<div class="title">
							Media
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			<li class="">
				<a href="help.html">
					<div>
						<div class="ico">
							<img src="../assets/img/ico/ico-help.gif">
						</div>
						<div class="title">
							Help
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			<li class="">
				<a href="#more">
					<div>
						<div class="ico">
							<img src="../assets/img/ico/ico-user.gif">
						</div>
						<div class="title">
							User
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			<li class="">
				<a href="#more">
					<div>
						<div class="ico">
							<img src="../assets/img/ico/ico-report.gif">
						</div>
						<div class="title">
							Report
						</div>
					</div>
					<div class="arrow">
						<div class="bubble-arrow-border"></div>
						<div class="bubble-arrow"></div>
					</div>
				</a>
			</li>
			<li class="">
				<a href="#" id="btn-more">
					<div>
						<div class="ico">
							<img src="../assets/img/ico/ico-more.png">
						</div>
						<div class="title">
							More
						</div>
					</div>
				</a>
			</li>
	 </ul>
	</aside>
	<div class="m-sidebar-collapsed">
		<ul class="nav nav-pills">
			
		</ul>
		<div class="arrow-border">
			<div class="arrow-inner"></div>
		</div>
	</div>
	<div class="main-container">
		<div class="container-fluid">
			<section>
				<div class="page-header">
					<h1>News Module</h1>
				</div>

<!-- Edit Modal -->

<div id="myModal" class="modal_edit_news fade">
    <div class="modal-header">
      <button class="close" data-dismiss="modal">&times;</button>
      <h3>Edit News</h3>
    </div>
    <div class="modal-body">            
       <div class="modal-body">  

             <div class="something" style="display:none;">
                    
             </div>
    </div>
    </div>
    <div class="modal-footer">
      <a href="#" class="btn btn-info" data-dismiss="modal" >Cancel</a>
    </div>
</div>
<!-- /Edit Modal -->


				<div id="fb-root"></div>

<div class="fb-comments" data-href="http://edu.technation.af" data-width="470" data-num-posts="10"></div>
				
				<div class="row-fluid">
					<div class="span4 m-widget">
					<?php 
						if (isset($_GET['update'])){
							if ($_GET['update']=='success'){
							?>
								<span class='span12 alert alert-success' style="margin-left:0;widht:100px;">News has been updated successfully!</span>	
							<?php
							}
							else{
							?>
								<span class='span12 alert alert-error' style="margin-left:0;widht:100px;">Error Occured! News NOT updated.</span>
							<?php
							}
						}
					?>
						<div class="m-widget-header">
						<div id='delete_result' class='alert' style='display:none'></div>
							<h4 class='text-info'><i class='icon-rss-sign'></i>&nbsp;Recent News</h4>
							
						</div>		
						<?php 
						$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
						if(!$link) {
							die('Failed to connect to server: ' . mysql_error());
						}
						
						//Select database
						$db = mysql_select_db(DB_DATABASE);
						if(!$db) {
							die("Unable to select database");
						}
						$userid = $_SESSION['SESS_USER_ID'];
						$select_user=mysql_query("SELECT * FROM perm_members where id='$userid'");
						$user_row=mysql_fetch_array($select_user);
						?>
						<div class="m-widget-body">
							<div id='retrieved-data'>
						   			<img src="images/ajax-loader.gif" />
						</div>
						</div>
					</div>
					<div class="span8 m-widget">
						<div class="m-widget-header">
						<?php
	if(isset($_GET['r']) and $_GET['r']=="s"){
		?>
	
		<span class='span12 alert alert-success'>News has been Published Successfully!</span>
		<?php 
	}
	else {
		echo "";
	}
	if(isset($_GET['r']) and $_GET['r']=="f"){
		
		?>
	<span class='span12 alert alert-error'>Unable to Add news!</span>
		
		<?php
	}
	else{
		echo "";
	}
	
?>
							<h3>Publish New</h3>
							
<form method="post" enctype="multipart/form-data" action="execute/update1_project.php" style="margin-top: 30px">							
<div class="form-horizontal">
  <fieldset>
    <div class="control-group">
      <!-- Username -->
      <label class="control-label">News Title: </label>
      <div class="controls">
        <input type="text" id="news_title" required name="news_title" placeholder="Please enter a News title..." class="span6">      </div>
    </div>

    <div class="control-group">
      <!-- E-mail -->
      <label class="control-label">Category:</label>
      <div class="controls">
        <?php //For Retrieving categories from DB 
			$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
			if(!$link) {
				die('Failed to connect to server: ' . mysql_error());
			}

			//Select database
			$db = mysql_select_db(DB_DATABASE);
			if(!$db) {
				die("Unable to select database");
			}
			?>
			<div id="news_cat_new" name="news_cat" style="display: none"></div>
			<?php
			$cat_qry = mysql_query("SELECT * FROM news_categories order by name asc");
			if($cat_qry){
				?>
				<select name="news_cat" id="news_cat" class="span6">
				<option value="">Please select a category...</option>
					<?php 
					while($cat_row=mysql_fetch_array($cat_qry)){
						?>
						<option value="<?php echo $cat_row['id']; ?>"><?php echo $cat_row['name']; ?></option>
						<?php
					}
					?>
				</select>
				<?php
			}	
			else{
				echo "QUERY FAILED: " . mysql_error();
			}
        ?>
        <span id="add_new" style="display:none"><input id="cat" type="text" class="span6" placeholder="New category name..."/><input type="button" id="submit_cat" class="btn span2" value="+Add" style="margin-left:10px;"/><input class="btn btn-danger span2" id="cancel" style="margin-left:10px;" value="-Cancel"></span>
        <a id="add_new_cat" style="margin-left:10px; cursor: hand; cursor:  pointer;">+Add New Category</a>
        <!-- <input type="text" id='news_cat' autocomplete="off" name='news_cat' placeholder='Hit a Key...' class="span6" id='cat' style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="[&quot;Fellowship&quot;,&quot;Scholarship&quot;,&quot;Internship&quot;,&quot;Course&quot;,&quot;Seminar&quot;,&quot;CSS&quot;,&quot;HTML&quot;,&quot;JavaScript&quot;,&quot;Python&quot;,&quot;Ruby&quot;,&quot;Ruby on Rails&quot;,&quot;API&quot;,&quot;Other...&quot;]"> -->
        <input type="hidden" id='user_id' name='user_id' value="<?php echo $user_row['id'];?>" >
        </div>
    </div>
 <div class="control-group">
      <!-- Username -->
      <label class="control-label">Description:</label>
      <div class="controls">
        <textarea class="span6" rows="3" placeholder="Max: 100 characters" name="desc"></textarea>
    </div>
    <div class="control-group">
      <!-- News Body-->
      <label class="control-label" for="password">News Body:</label>
      <div class="controls">
     <div id="alerts"></div>
    <div class="btn-toolbar" data-role="editor-toolbar" data-target="#editor">
     <div class="btn-group">
        <a class="btn dropdown-toggle" data-toggle="dropdown" title="Font Size"><i class="icon-text-height"></i>&nbsp;<b class="caret"></b></a>
          <ul class="dropdown-menu">
          <li><a data-edit="fontSize 5"><font size="5">Big</font></a></li>
          <li><a data-edit="fontSize 3"><font size="3">Medium</font></a></li>
          <li><a data-edit="fontSize 1"><font size="1">Small</font></a></li>
          </ul>
      </div>
      <div class="btn-group">
        <a class="btn" data-edit="bold" title="Bold (Ctrl/Cmd+B)"><i class="icon-bold"></i></a>
        <a class="btn" data-edit="italic" title="Italic (Ctrl/Cmd+I)"><i class="icon-italic"></i></a>
        <a class="btn" data-edit="underline" title="Underline (Ctrl/Cmd+U)"><i class="icon-underline"></i></a>
      </div>
     <div class="btn-group">
        <a class="btn" data-edit="justifyleft" data-toogle="tooltip" title="Align Left (Ctrl/Cmd+L)"><i class="icon-align-left"></i></a>
        <a class="btn" data-edit="justifycenter" title="Center (Ctrl/Cmd+E)"><i class="icon-align-center"></i></a>
        <a class="btn" data-edit="justifyright" title="Align Right (Ctrl/Cmd+R)"><i class="icon-align-right"></i></a>
        <a class="btn" data-edit="justifyfull" title="Justify (Ctrl/Cmd+J)"><i class="icon-align-justify"></i></a>
      </div>
      <div class="btn-group">
        <a class="btn" data-edit="insertunorderedlist" title="Bullet list"><i class="icon-list-ul"></i></a>
        <a class="btn" data-edit="insertorderedlist" title="Number list"><i class="icon-list-ol"></i></a>
      </div>
     <div class="btn-group">
		  <a id="show_link" class="btn" title="Hyperlink"><i class="icon-link"></i></a>
		    <div class="dropdown-menu input-append" id="link" style="display:none;">
			    <input class="span9" placeholder="URL" type="text" data-edit="createLink"/>
			    <button class="btn" type="button">Add</button>
        	</div>
        <a class="btn" data-edit="unlink" title="Remove Hyperlink"><i class="icon-cut"></i></a>

      </div>
        <a class="btn btn_insert" title="Insert picture (or just drag & drop)" id="pictureBtn"><i class="icon-picture"></i></a>
        <input id="imgbtn" style="display:none;" type="file" data-role="magic-overlay" data-target="#pictureBtn" data-edit="insertImage" />
     </div>

    <div id="editor"></div>
    <textarea rows="7" id='show' style="display:none;" name='news_body' class='span11' required></textarea>
      </div>

		</br>
      <div class="control-group">
      <label class="control-label" >Upload image: </label>
      <div class="controls">	
      
		<input type="file" name="photoimg" id="photoimg" required/>
		
		</br>
		
		</div>
		
		</div>
      
    </div>
 
   
 
    <div class="control-group">
      <!-- Button -->
      <div class="controls">
        <input type="submit" data-toogle="tooltip" title="Press to Publish News" class="btn btn-success span4" id='add_news_btn' value="Publish"/>
      </div>
    </div>
  </fieldset>
</div>
</form>							
						</div>
						<div class="m-widget-body">
							<div class="row-fluid" id="updateResult">
											
							</div>
						</div>
					</div>
				</div>
				
			</section>
		</div>
	</div>
</body>
</html>